import Vue from "vue";
import App from "./App.vue";

import router from "./router";

Vue.config.productionTip = false;

new Vue({
  render: (h) => h(App),
  router,
}).$mount("#app");

//路由全局守卫
router.beforeEach((to, from, next) => {
  console.log(to, from, next);
  // next();
  const isLogin = localStorage.getItem("userInfo");
  if (isLogin) {
    //如果已经登录
    if (to.path === "/login") {
      //并且你在login页面，你要跳到首页
      next("/");
    } else {
      //用户已经登录并且不在login路由
      next();
    }
  } else {
    if (to.path === "/login") {
      next();
    } else {
      next("/login");
    }
  }
});
//后置钩子 通俗的讲就是把着最后一关，
router.afterEach((to, from) => {
  console.log(to, from);
  // alert("我进来了");
});
